package com.boco.ibssystem.common.provider;

import com.boco.biinjectionserviceapi.model.config.DataSourceConfigInfo;
import com.boco.biinjectionserviceapi.service.config.IDataSourceConfigInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * Created by yfyuan on 2016/8/15.
 */
@Service
public class DataProviderManager {

    @Autowired
    private IDataSourceConfigInfoService dataSourceConfigInfoService;

    public DataProvider getDataProvider(Long datasourceId) {
        DataProvider dataProvider = DataProvider.getInstance(datasourceId);
        if(dataProvider==null){
            DataSourceConfigInfo configInfo = dataSourceConfigInfoService.getById(datasourceId);
            dataProvider=DataProvider.buildDataProvider(configInfo.getId(),configInfo.getDataSourceName(),configInfo.getType(),configInfo.getDriverClassName(),configInfo.getJdbcUrl(),configInfo.getUsername(),configInfo.getPassword());
        }
        return dataProvider;
    }
}
